﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OpenESSOConfigurator.PresentationLayer.EventBroker;
using OpenESSOConfigurator.PresentationLayer.PresentationModels;
using OpenESSOConfigurator.PresentationLayer.EventBroker.Handlers;
using OpenESSOConfigurator.BusinessLayer.Atoms;
using OpenESSOConfigurator.BusinessLayer.Stores;

namespace OpenESSOConfigurator.PresentationLayer.UserControls
{
    public partial class RightSpine : UserControl,IView
    {
        public RightSpine()
        {
            InitializeComponent();
        }

        private void HideUC()
        {
            foreach (Control UC in this.Controls)
            {
                UC.Dispose();
            }
        }

        [EventSubscription("topic://ItemTreePresentationModel/SelectedWinApplicationChanged", typeof(Publisher))]
        public void LoadApplicationView(object sender, EventArgs e)
        {
            HideUC();
            WinApplicationPresentationModel.Instance.WinApplication = (WinApplication)sender;
            this.applicationConfig1 = new OpenESSOConfigurator.PresentationLayer.UserControls.ApplicationConfig();
            this.Controls.Add(applicationConfig1);
            this.applicationConfig1.Dock = DockStyle.Fill;
        }

        [EventSubscription("topic://ItemTreePresentationModel/SelectedWinFormChanged", typeof(Publisher))]
        public void LoadWinFormView(object sender, EventArgs e)
        {
            HideUC();
            WinFormPresentationModel.Instance.WinForm = (WinForm)sender;
            this.winFormConfig1 = new OpenESSOConfigurator.PresentationLayer.UserControls.WinFormView();
            this.Controls.Add(winFormConfig1);
            this.winFormConfig1.Dock = DockStyle.Fill;
        }


        [EventSubscription("topic://ItemTreePresentationModel/SelectedCSGChanged", typeof(Publisher))]
        public void LoadCSGView(object sender, EventArgs e)
        {
            HideUC();
            CSGPresentationModel.Instance.CredentialSharingGroup = (CredentialSharingGroup)sender;
            this.CSGConfig1 = new OpenESSOConfigurator.PresentationLayer.UserControls.CSGConfig();
            this.Controls.Add(CSGConfig1);
            this.CSGConfig1.Dock = DockStyle.Fill;
        }

        [EventSubscription("topic://ItemTreePresentationModel/SelectedPasswordPolicyChanged", typeof(Publisher))]
        public void LoadPasswordPolicyView(object sender, EventArgs e)
        {
            HideUC();
            PasswordPolicyPresentationModel.Instance.PasswordPolicy = (PasswordPolicy)sender;
            this.passworPolicyConfig1 = new OpenESSOConfigurator.PresentationLayer.UserControls.PassworPolicyConfig();
            this.Controls.Add(passworPolicyConfig1);
            this.passworPolicyConfig1.Dock = DockStyle.Fill;
        }

        [EventSubscription("topic://ItemTreePresentationModel/SelectedConfigurationStoreChanged", typeof(Publisher))]
        public void LoadConfigurationStoreView(object sender, EventArgs e)
        {
            HideUC();
            ConfigurationStorePresentationModel.Instance.ConfigurationStore = (ConfigurationStore)sender;
            this.confStoreView1 = new OpenESSOConfigurator.PresentationLayer.UserControls.ConfStoreView();
            this.Controls.Add(confStoreView1);
            this.confStoreView1.Dock = DockStyle.Fill;
        }

        private void RightSpine_Load(object sender, EventArgs e)
        {
            ItemTreePresentationModel.Instance.RegisterView(this);
        }

    }
}
